(:
  gets some basic info on a coffee file
:)

declare boundary-space strip;
import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;
import module namespace
    coffee = "http://tatiana.emse.fr/coffee"
    at "coffee-utils.xq" ;
    
declare variable $t := $arguments[1];
declare variable $doc := doc($t);
declare variable $version := coffee:get-version($doc);
declare variable $msgs := coffee:get-messages($doc);

<display>{

<item><info name="name">Coffee version</info><info name="value">{
	if ($version eq 100) then "alpha"
	else if ($version eq 104) then "alpha+"
	else if ($version eq 200) then "somewhere between alpha+ and beta-"
	else "dunno"
}</info></item>,
let $steps := for $msg in $msgs return coffee:get-step($msg)
for $step in fn:distinct-values($steps)
return <item>
<info name="name">step</info><info name="value">{$step}</info>
<info name="count">{fn:count(for $g in $steps where $g = $step return $g)}</info>
</item>,
let $groups := for $msg in $msgs return coffee:get-group($msg)
for $group in fn:distinct-values($groups)
order by $group
return <item><info name="name">group</info><info name="value">{$group}</info>
<info name="count">{fn:count(for $g in $groups where $g = $group return $g)}</info>
</item>,
let $tools := for $msg in $msgs return coffee:get-tool($msg)
for $tool in fn:distinct-values($tools)
return <item><info name="name">tool</info><info name="value">{$tool}</info>
<info name="count">{fn:count(for $g in $tools where $g = $tool return $g)}</info>
</item>,
let $users := for $msg in $msgs where coffee:get-tool($msg) return coffee:get-username($msg)
for $user in fn:distinct-values($users)
where ($user!="" and $user!="SERVER")
order by fn:lower-case($user) 
return <item><info name="name">user</info><info name="value">{$user}</info>
<info name="count">{fn:count(for $g in $users where $g = $user return $g)}</info>
</item>
}</display>
